package com.example.demo;

import android.graphics.Bitmap;
import android.util.Log;
import android.util.LruCache;

import com.android.volley.toolbox.ImageLoader;

class MyImageCache implements ImageLoader.ImageCache {
    private static final String TAG = "MyImageCache";
    private LruCache<String,Bitmap> lruCache;

    public MyImageCache(){
        //最大内存
        int maxsize = 10*1024*1024;
        lruCache = new LruCache<String, Bitmap>(maxsize){
            @Override
            protected int sizeOf(String key, Bitmap value) {
                //图片字节 * 高
                return value.getRowBytes()*value.getHeight();
            }
        };
    }

    @Override
    public Bitmap getBitmap(String s) {
        Bitmap bitmap = lruCache.get(s);
        if (bitmap==null){
            Log.e(TAG,"getBitmap bitmap==null");
        }else {
            Log.e(TAG, "getBitmap success　bitmap！=null");
        }
        return bitmap;
    }

    @Override
    public void putBitmap(String s, Bitmap bitmap) {
        if (bitmap==null){
            Log.e(TAG,"putBitmap failed bitmap==null");
        }else{
            Log.e(TAG, "putBitmap success　bitmap！=null");
        }
        lruCache.put(s,bitmap);
    }
}
